
<!-- 产品指南 -->
<template>
  <div class="page-box h100 display-flex czbj">
    <dxtable
      :dataJson="dataJson"
      :portUrl="portUrl"
      :sonRouter="sonRouter"
      :qx="qx"
      :headBtn="headBtn"
      ref="databale"
    ></dxtable>
  </div>
</template>
 <script lang='ts' setup>
import dxtable from "../../../components/util/dxtable.vue";
import sort from "../../../components/util/sort.vue";
import { NSwitch } from "naive-ui";
import { dxget, dxpost, qurl } from "../../../util/index";
import { h, ref, reactive } from "vue";
const cz = qurl();
const databale = ref();
const props = defineProps({
  pup: { type: String },
});
const emit = defineEmits(["callBack"]);
const initeer = () => {
  databale.value.initDataExpose();
};
// 弹窗公用该列表
let dataJson = [
  {
    title: "id",
    key: "id",
    width: 80,
  },
  {
    title: "封面",
    width: 160,
    render(row) {
      return h("img", { src: row.fm, class: "fnhhbwerw" });
    },
  },
  {
    title: "产品标题",
    key: "title",
    search: true, // 是否在搜索栏展示
  },
  {
    title: "产品类型",
    search: true, // 是否在搜索栏展示
    width: "160",
    key: "dxleujne",
    type: "select",
    options: [
      {
        label: "全部",
        value: null,
      },
      {
        label: "交流充电桩",
        value: 1,
      },
      {
        label: "直流充电桩",
        value: 2,
      },
      {
        label: "大功率液冷超充系统",
        value: "3",
      },
    ],
    render(row) {
      switch (row.dxleujne) {
        case 1:
          return "交流充电桩";
          break;
        case 2:
          return "直流充电桩";
          break;
        case 3:
          return "大功率液冷超充系统";
          break;
      }
    },
  },
  {
    title: "是否首页案例展示",
    width: "160",
    render(row) {
      let hgvse = false;
      if (row.sstj == 1) {
        hgvse = true;
      }
      return h(NSwitch, {
        "default-value": hgvse,
        "on-update:value": (e) => {
          xiugai({
            id: row.id,
            sstj: e,
          });
        },
      });
    },
  },
  {
    title: "排序",
    width: 100,
    render(row) {
      row.databaseName = "abbproduct";
      return h(sort, {
        row,
        onCallBack: () => {
          initeer();
        },
      });
    },
  },
  {
    title: "添加时间",
    key: "addTime",
    width: "200",
  },
];
let portUrl = "abb/abbproduct";
let headBtn = [];
let pupVal = cz.pup || props.pup;
if (pupVal) {
  portUrl = "abb/abbproduct?dxleujne=" + pupVal;
  dataJson = [
    {
      title: "封面",
      width: 160,
      render(row) {
        return h("img", { src: row.fm, class: "fnhhbwerw" });
      },
    },
    {
      title: "产品标题",
      key: "title",
      search: true, // 是否在搜索栏展示
    },
  ];

  headBtn = [
    {
      name: "确认选择 ",
      async clickFun(row) {
        const arrList = row.join(",");
        const res = await dxpost("abb/util/homepageRecommendation", {
          dataBase: "abbproduct",
          xgdata: arrList,
          type: pupVal,
        });
        emit("callBack");
      },
    },
  ];
}
const qx = {
  DeletePermissionID: "abbProductGuideListdel", //删除
  EditPermissionIdentifier: "abbProductGuideListbj", // 编辑
  NewPermissionIdentifier: "abbProductGuideListxz", // 新建
  ViewPermissionID: "abbProductGuideListck", // 查看
};

const sonRouter = "EdutProductGuide";

const xiugai = async (obj) => {
  const res = await dxpost("abb/abbproduct", obj, "PUT");
  console.log(res);
};
</script>
 <style scoped>
</style>